package com.njtoyo.taxi.admin.rest.controller.business.customer;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.njtoyo.taxi.admin.aop.PermissionScope;
import com.njtoyo.taxi.admin.rest.presenter.business.CustomerLogoutListPresenter;
import com.njtoyo.taxi.admin.rest.wrapper.business.customer.ReasonWrapper;
import com.njtoyo.taxi.admin.rest.wrapper.business.customer.logout.IndexQueryWrapper;
import com.njtoyo.taxi.admin.service.business.customer.CustomerLogoutService;
import com.taxi.entity.common.RestResult;
import com.njtoyo.taxi.entity.backend.AdminUser;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.validation.Valid;

@RestController
@RequestMapping("business/customer/logout")
@Api(value = "乘客注销管理", tags = "乘客注销管理")
public class CustomerLogoutController {

    @Autowired
    private CustomerLogoutService customerLogoutService;

    @GetMapping("")
    @ApiOperation(value = "乘客注销记录", notes = "获取乘客申请注销列表，权限：customer_logout")
    @PermissionScope(names = {"customer_logout"})
    RestResult<IPage<CustomerLogoutListPresenter>> index(@Valid IndexQueryWrapper listWrapper) {
        return customerLogoutService.getAllPage(listWrapper);
    }

    @PostMapping("/{id}/agree")
    @ApiOperation(value = "同意注销", notes = "同意乘客注销，权限：customer_logout_agree")
    @PermissionScope(names = {"customer_logout_agree"})
    RestResult agree(@ApiIgnore @ModelAttribute("admin") AdminUser adminUser, @PathVariable("id") Long id) {
        return customerLogoutService.agree(adminUser, id);
    }

    @PostMapping("/{id}/reject")
    @ApiOperation(value = "拒绝注销", notes = "拒绝乘客注销，权限：customer_logout_reject")
    @PermissionScope(names = {"customer_logout_reject"})
    RestResult reject(@ApiIgnore @ModelAttribute("admin") AdminUser adminUser, @PathVariable("id") Long id) {
        return customerLogoutService.reject(adminUser, id);
    }

    @PatchMapping("/{id}")
    @ApiOperation(value = "填写注销原因", notes = "填写注销原因，权限：customer_logout_reason")
    @PermissionScope(names = {"customer_logout_reason"})
    RestResult reason(@PathVariable("id") Long id, @Valid @RequestBody ReasonWrapper wrapper) {
        return customerLogoutService.reason(id, wrapper);
    }
}
